{include file="public/header" /}

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑用户</h5>
                    <h5 style="float:right">
                        <a href="{:url('index')}" style="color:green">返回列表 ></a></h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add" id="add" method="post">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">ID：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$customer.id}" readonly >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">昵称：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$customer.nickname}" readonly >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">注册时间：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$customer.create_time}" readonly >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">推广位：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$customer.yx_pid}" readonly >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限：</label>
                            <div class="input-group col-sm-4">
                                <select name="current_level" id="current_level" class="form-control">
                                    <option {$customer.current_level == '0' ? 'selected' : ''} value="0">普通会员</option>
                                    <option {$customer.current_level == '1' ? 'selected' : ''} value="1">店长</option>
                                    <option {$customer.current_level == '2' ? 'selected' : ''} value="2">超级店长</option>
                                    <option {$customer.current_level == '3' ? 'selected' : ''} value="3">总代理</option>
                                </select>
                                <span class="input-group-btn">
                                    <button type="button" onclick="changeLevel()" class="btn btn-primary">
                                        <i class="fa fa-check"></i> 修改</button>
                                </span>
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">收益状态：</label>
                            <div class="input-group col-sm-4">
                                {:getEnumSelectWidget(config("enum.customerStatus"), 'customer_status', '-请选择我的收益状态-', $customer['status'], 1)}
                                <span class="input-group-btn">
                                    <button type="button" onclick="changeCustomerStatus()" class="btn btn-primary">
                                        <i class="fa fa-check"></i> 修改</button>
                                </span>
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">上级：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{:empty($parentCustomer) ? '--' : $parentCustomer.nickname}" readonly >
                                <span class="input-group-btn">
                                    <button type="button" onclick="showParentCustomer()" class="btn btn-primary">
                                        <i class="fa fa-info"></i> 查看</button>
                                </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">下级：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$childCustomerNumber}人" readonly >
                                <span class="input-group-btn">
                                    <a href="{:url('childCustomerList', ['customer_id'=>$customer.id])}"
                                        class="btn btn-primary"><i class="fa fa-info"></i> 查看</a>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">收益：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$customer.history_profit}" readonly >
                                <span class="input-group-btn">
                                    <a href="{:url('profit', ['customer_id'=>$customer.id])}" class="btn btn-primary"><i class="fa fa-info"></i> 查看</a>
                                </span>
                            </div>
                        </div>

                        <!--<div class="form-group">
                            <label class="col-sm-3 control-label">历史订单：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" value="{$customer.total_settle_number}单" readonly >
                                <span class="input-group-btn">
                                    <a href="{:url('historyOrderList', ['customer_id'=>$customer.id])}" class="btn btn-primary"><i class="fa fa-info"></i> 查看</a>
                                </span>
                            </div>
                        </div>-->
                        <div class="hr-line-dashed"></div>
                        <!--<div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button id="formSubmit" type="submit" class="btn btn-primary"><i class="fa fa-check"></i> 提交</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>-->
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
function changeLevel() {

    var currentLevel = $("#current_level").val();

    $.ajax({
        url: "{:url('checkCurrentLevel')}",
        type: "post",
        data: {
            current_level: currentLevel,
            customer_id: '{$customer.id}'
        },
        dataType: "json",
        beforeSend:function() {
            // 显示loading
            index2 = layer.load(0, {
                shade: [0.3,'#fff']
            });
        },
        success:function(data) {

            if (data['code'] != 1) {

                // 如果data等于 confirm 表示需要谈 确认框
                if (data['data'] == 'confirm') {
                    layer.confirm(data.msg, {icon: 3}, function(index){
                        changeLevelPost(currentLevel);
                    });
                    return false;
                }

                layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                    layer.close(index)
                });
                return false;
            }

            layer.confirm(data.msg, {icon: 3}, function(index){
                changeLevelPost(currentLevel)
            });
        },
        complete:function() {
            // 隐藏loading
            layer.close(index2);
        }
    });

}

function changeLevelPost(currentLevel) {

    $.ajax({
        url: "{:url('changeCurrentLevel')}",
        type: "post",
        data: {
            current_level: currentLevel,
            customer_id: '{$customer.id}'
        },
        dataType: "json",
        beforeSend:function() {
            // 显示loading
            index2 = layer.load(0, {
                shade: [0.3,'#fff']
            });
        },
        success:function(data) {

            if (data['code'] != 1) {

                layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                    layer.close(index)
                });
                return false;
            }

            layer.msg(data.msg, {icon: 1,time:1000,shade:0.1});
        },
        complete:function() {
            // 隐藏loading
            layer.close(index2);
        }
    });
}

function changeCustomerStatus() {
    layer.confirm('确认修改？', {icon: 3}, function(index){
        $.ajax({
            url: "{:url('changeCustomerStatus')}",
            type: "post",
            data: {
                customer_status: $("#customer_status").val(),
                customer_id: '{$customer.id}'
            },
            dataType: "json",
            beforeSend:function() {
                // 显示loading
                index2 = layer.load(0, {
                    shade: [0.3,'#fff']
                });
            },
            success:function(data) {

                if (data['code'] != 1) {

                    layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                        layer.close(index)
                    });
                    return false;
                }

                layer.msg(data.msg, {icon: 1,time:1000,shade:0.1});
            },
            complete:function() {
                // 隐藏loading
                layer.close(index2);
            }
        });
    })
}

function showParentCustomer() {
    var parentCustomer = '{$parentCustomer}';

    if (common.isNullOrEmpty(parentCustomer)) {
        layer.msg('暂时没有上级');
        return false;
    }

    window.location.href="{:url('parentCustomerInfo')}?customer_id="+'{$customer.id}'
}
</script>
</body>
</html>